package com.ugoodtech.mdcc.core.repository;

import com.ugoodtech.mdcc.core.domain.StationReport;
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

public interface StationReportRepository extends PagingAndSortingRepository<StationReport, Long>
        , QueryDslPredicateExecutor<StationReport> {

    @Query("from StationReport where station_id=:stationId and deleted=false and enabled=true and category='techcolor_report'")
    StationReport selectReport(@Param("stationId") Long stationId);

    @Query("from StationReport where station_id in :stationId and deleted=false and enabled=true "
        + "and category='techcolor_report'")
    List<StationReport> selectReport(@Param("stationId") List<Long> stationId);

    @Query("from StationReport where station_id=:stationId and deleted=false and enabled=true and category='service_report'")
    StationReport selecServicetReport(@Param("stationId") Long stationId);

    @Query(value = "SELECT *,MIN(creation_time) FROM station_report WHERE category=:category and station_id=:stationId", nativeQuery = true)
    StationReport selectMinTimeReport(@Param("stationId") Long stationId, @Param("category") String category);

    @Query("from StationReport where station_id=:stationId and deleted=false and enabled=true and category='techcolor_report' and auditing=1")
    StationReport selectColorReport(@Param("stationId") Long stationId);
}
